package com.aj.service;

import com.aj.Interface.CheckService;
import com.aj.dao.CheckDao;
import com.aj.pojo.CheckItem;
import com.aj.pojo.User;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass =CheckService.class )
@Transactional
public class CheckServiceImpl implements CheckService{

    @Autowired
private CheckDao checkDao;


    /**
     * 新增检查项
     * @param checkItem
     */
    @Override
    public void add(CheckItem checkItem) {
        checkDao.add(checkItem);
    }


    /**
     * 分页查询
     * @param
     * @return
     */
    @Override
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage, pageSize);
        Page<CheckItem>  Page=  checkDao.findPage(queryString);

        return new PageResult(Page.getTotal(),Page.getResult());
    }


    /**
     * 根据id删除
     * @param id
     */
    @Override
    public void delete(Integer id) {
        long findgrounp = checkDao.findgrounp(id);
        if (findgrounp>0){
            throw new RuntimeException("该检查项被引用,无法删除");
        }else {
            checkDao.delete(id);
        }

    }


    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public CheckItem findbyid(Integer id) {
        CheckItem checkItem= checkDao.findbyid(id);
        return checkItem;
    }

    /**
     * 更新
     * @param checkItem
     */
    @Override
    public void update(CheckItem checkItem) {

        checkDao.update(checkItem);
    }


    /**
     * 查询所有
     * @return
     */
    @Override
    public List<CheckItem> findall() {
        List<CheckItem>  checkItems = checkDao.findall();
        return checkItems;
    }


}
